<?php

class CompanyMapper extends AbstractMapper
{

    protected function _init()
    {
	$this->setModel(new CompanyModel());
	$this->setTableName(COMPANY_TABLE);
    }

    public function getSimilarCompanies($id, $activityId, $limit = 5)
    {
	if (!$activityId) {
	    return false;
	}

	$sql = $this->createSqlCommand()
		->select("*")
		->from($this->getTableName())
		->where("activity_id = :activity_id AND id != :id", array(":activity_id" => $activityId, ":id" => $id))
		->order("RAND()")
		->limit($limit);
	return $this->getObjectList($sql->queryAll());
    }

    public function getByUserId($id, $page = 1, $limit = 10)
    {
	if (!$id) {
	    return false;
	}
	$sql = $this->createSqlCommand()
		->select("*")
		->from($this->getTableName())
		->where("user_id = :user_id", array(':user_id' => $id))
		->limit($limit)
		->offset(($page - 1) * $limit);
	
	return $this->getObjectList($sql->queryAll());
    }

}
